﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SCRUM.Core.BusinessObjects
{
    /// <summary>
    /// Business object for work progress.
    /// </summary>
	[Serializable()]
    public class WorkProgress : BusinessObject
    {
        /// <summary>
        /// ID of the associated user.
        /// </summary>
        private int userID;

        /// <summary>
        /// ID of the associated task.
        /// </summary>
        private int taskID;

        /// <summary>
        /// Initializes a new instance of the <see cref="WorkProgress"/> class.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="userID">The user ID.</param>
        /// <param name="taskID">The task ID.</param>
        /// <param name="date">The date.</param>
        /// <param name="storyPoints">The story points.</param>
        /// <param name="note">The note.</param>
        public WorkProgress(int id, int userID, int taskID, DateTime date, double storyPoints, string note)
            :base(id)
        {
            this.userID = userID;
            this.taskID = taskID;
            this.Date = date;
            this.StoryPoints = storyPoints;
            this.Note = note;
        }

        /// <summary>
        /// Gets the name of the task.
        /// </summary>
        /// <value>The name of the task.</value>
        public string TaskName
        {
            get
            {
                return this.AssociatedTask.Name;
            }
        }

        /// <summary>
        /// Associated task.
        /// </summary>
        protected Task associatedTask;

        /// <summary>
        /// Gets or sets the associated task.
        /// </summary>
        /// <value>The associated task.</value>
        public Task AssociatedTask 
        {
            get
            {
                if (this.associatedTask == null)
                {
                    return DAO.DAOTask.GetTaskByID(this.taskID);
                }
                else
                {
                    return this.associatedTask;
                }
            }
            set
            {
                this.associatedTask = value;
            }
        }

        /// <summary>
        /// Associated user.
        /// </summary>
        protected User associatedUser;

        /// <summary>
        /// Gets or sets the associated user.
        /// </summary>
        /// <value>The associated user.</value>
        public User AssociatedUser 
        {
            get
            {
                if (this.associatedUser == null)
                {
                    return DAO.DAOUser.GetByID(this.userID);
                }
                else
                {
                    return this.associatedUser;
                }
            }
            set
            {
                this.associatedUser = value;
            }
        }

        /// <summary>
        /// Gets or sets the date.
        /// </summary>
        /// <value>The date.</value>
        public DateTime Date { get; set; }

        /// <summary>
        /// Gets or sets the story points.
        /// </summary>
        /// <value>The story points.</value>
        public double StoryPoints { get; set; }

        /// <summary>
        /// Gets or sets the note.
        /// </summary>
        /// <value>The note.</value>
        public string Note { get; set; }
    }
}
